const mongoose = require('mongoose');
const { Article } = require('../../model/article')
module.exports = async (req, res) => {
    var article = req.fields
    //创建简介
    article.about = article.about.substr(0, 70) + '......'
    article.words = (article.content.length / 1000).toFixed(1) + "K"
    article.readtime = Math.ceil(article.content.length / 500) + "min"
    try {
        var data = await Article.create(article)
    } catch {
        console.log(data);
        return res.send({
            data: null,
            meta: {
                status: 401,
                msg: '添加失败'
            }
        })
    }
    res.send({
        data: null,
        meta: {
            status: 201,
            msg: '添加成功'
        }
    })
}